package com.yonyou;

import java.util.ArrayList;
import java.util.List;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.netflix.feign.EnableFeignClients;
import org.springframework.cloud.netflix.hystrix.EnableHystrix;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.yonyou.common.service.messagecenter.util.HttpClientUtil;
import com.yonyou.common.service.messagecenter.util.HttpUtil;
import com.yonyou.common.service.messagecenter.util.MqConsts;

import net.sf.json.JSONObject;

@SpringBootApplication
@EnableCircuitBreaker
@EnableHystrix
@EnableFeignClients
@EnableDiscoveryClient
@Controller
public class MarketingServiceMqcenterApplication {

	public static void main(String[] args) {
		SpringApplication.run(MarketingServiceMqcenterApplication.class, args);
	}

    @RequestMapping(value = "/mqtest")
    @ResponseBody
    public  String available() {

    	long startTime=System.currentTimeMillis();

    	MyRunnable runnable = new MyRunnable();
    	List<Thread> list = new ArrayList<Thread>();  
    	  
        for (int i = 1; i <= 100; i++)  
        {  
        	Thread my = new Thread(runnable);
        	try{
                my.start();  
        	}catch(Exception e){
        		e.printStackTrace();
        	}
            list.add(my);  
        }  
  
        try  
        {  
            for (Thread my : list)  
            {  
                my.join();  
            }  
        }  
        catch (InterruptedException e)  
        {  
            e.printStackTrace();  
        }  
    	long endTime=System.currentTimeMillis(); //获取结束时间  
    	System.out.println("程序运行时间： "+(endTime-startTime)/1000+" s");  
        return "程序运行时间： "+(endTime-startTime)/1000+" s";
    }
    
    
    @RequestMapping(value = "/mqreceive", method = RequestMethod.POST)
    @ResponseBody
    public  String mqreceive() {
         return "{result\":\"200\"}";    	
    }
}

class MyRunnable implements Runnable{
	 
	 public MyRunnable() {
	 
	 }
	 
	 @Override
	 public void run() {

	    	long startTime=System.currentTimeMillis();//10.180.8.212
	    	String host="localhost";//"10.180.8.212";//
	    	String data="sadfsfsafsddddfsdffsadfsdfdddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddsadfsfsafsddddfsdffsadfsdfdddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddfffffffffffffffffffffsdfsdfaaaaaaaaaaaaadfsafasfasfasfsafasf12312222222222222222222222222sad55555555555555555555555555555555555555555555555555555555555555555555555555ggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbgggvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv6666666666666666666666666666666666666666666uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu666iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii44444444444";
	    	String url="";//"http://"+host+":8002/message/exchange?channel=exchange1&appid=2&sign=00002dfed24a7328cce90f5706b9e807c&occurtime=2016-12-26&nonce=123";
	    	for(int i=1;i<=150;i++){
//	    		try {
//					Thread.sleep(3000l);
//				} catch (InterruptedException e) {
//					// TODO Auto-generated catch block
//					e.printStackTrace();
//				}
	    		url="http://"+host+":8002/message/exchange?channel=exchange1&appid=2&sign="+i+"dfed24a7328cce90f5706b9e807c&occurtime=2016-12-26&nonce=123";
	        	HttpClientUtil.sendPostRequest(url, "{\"occurtime\":\""+data+"\"}");//+data+data+data+data
	    	}
	    	long endTime=System.currentTimeMillis(); //获取结束时间  
	    	System.out.println(Thread.currentThread().getId()+"程序运行时间： "+(endTime-startTime)+" ms");   
	 }
	}
